﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KPI.Utility
{
    public class EntityBase
    {
        public DateTime CreatedDate { get; set; }
        public DateTime? LastModifiedDate { get; set; }
        public int Version { get; set; }
        public bool IsDeleted { get; set; }

        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="copy">The copy.</param>
        /// <returns>Copy version</returns>
        public virtual EntityBase Copy(EntityBase copy)
        {
            copy.CreatedDate = this.CreatedDate;
            copy.IsDeleted = this.IsDeleted;
            copy.LastModifiedDate = this.LastModifiedDate;
            copy.Version = this.Version;
            return copy;
        }

        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <typeparam name="T">Must inherited from EntityBase</typeparam>
        /// <param name="copy">The copy.</param>
        /// <returns>Copy version</returns>
        public virtual T Copy<T>(T obj) where T : EntityBase
        {
            obj.CreatedDate = this.CreatedDate;
            obj.IsDeleted = this.IsDeleted;
            obj.LastModifiedDate = this.LastModifiedDate;
            obj.Version = this.Version;
            return obj;
        }

    }
}
